# import os
# from openai import OpenAI

# client = OpenAI(
#     # 若没有配置环境变量，请用百炼API Key将下行替换为：api_key="sk-xxx",
#     api_key="sk-f30f096e716f4bf3847df42b880801ed",
#     base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
# )
# completion = client.chat.completions.create(
#     model="qwen-vl-plus",  # 此处以qwen-vl-plus为例，可按需更换模型名称。模型列表：https://help.aliyun.com/zh/model-studio/getting-started/models
#     messages=[{"role": "user","content": [
#             {"type": "text","text": "这道菜的名字是什么？它的食材和配料是什么？制作这道菜的步骤是什么？请按照”1.菜名，2.食材和配料及热量和营养信息，3.步骤“的格式回答。"},
#             {"type": "image_url",
#              "image_url": {"url": "https://xiaoxiaobaiyang.oss-cn-shenzhen.aliyuncs.com/food_moment_discover/train/img/0/1.jpg"}}
#             ]}]
#     )
# print(completion.model_dump_json())

# import json
#
# data = '''{"id":"chatcmpl-48dbbf54-5250-970e-997c-cdba1105cd8f","choices":[{"finish_reason":"stop","index":0,"logprobs":null,"message":{"content":"1. 菜名：红烧鸡翅\\n\\n2. 食材和配料：\\n   - 主料：鸡中翅8个（约400克）\\n   - 辅料：生姜适量、大蒜瓣5颗、生抽酱油适量、老抽酱油少许、白糖适量、盐适量、清水适量、食用油适量。\\n   \\n   热量与营养信息:\\n   每份大约含有367卡路里, 包含蛋白质39g, 脂肪22g, 碳水化合物1g。\\n\\n3. 制作步骤：\\n\\na) 准备材料：将鸡中翅清洗干净后用刀在两面各划上几刀以便入味；准备姜片、蒜瓣备用；\\nb) 锅内热油，放入切好的姜片和蒜瓣爆香；\\nc) 加入处理过的鸡中翅翻煎至微黄；\\nd) 倒入生抽酱油、老抽酱油调味，并加入糖继续炒匀至上色均匀；\\ne) 往锅中倒入足够的热水没过鸡肉，盖好锅盖转小火慢炖煮熟透即可出锅装盘享用。","refusal":null,"role":"assistant","audio":null,"function_call":null,"tool_calls":null}}],"created":1739955751,"model":"qwen-vl-plus","object":"chat.completion","service_tier":null,"system_fingerprint":null,"usage":{"completion_tokens":257,"prompt_tokens":173,"total_tokens":430,"completion_tokens_details":null,"prompt_tokens_details":null}}'''
#
# parsed_data = json.loads(data)
# content = parsed_data['choices'][0]['message'].get("content","")
#
# print(content)

# import re
# import json

# # 给定的内容
# content = """1. 菜名：红烧鸡翅

# 2. 食材和配料：
#    - 主料：鸡中翅8个（约400克）
#    - 辅料：生姜适量、大蒜瓣5颗、生抽酱油适量、老抽酱油少许、白糖适量、盐适量、清水适量、食用油适量。

# 热量与营养信息:
# - 每份(以一个鸡翅为单位)大约含有167卡路里。
# - 这些食物富含蛋白质、脂肪以及一些维生素B群等微量元素。

# 3. 制作步骤：

# a）将买回来的新鲜鸡翅膀清洗干净后用刀在两面各划上几刀以便入味；
# b）锅内加入少量水加热至沸腾,放入切好的姜片煮出香味； 
# c）然后把处理过的鸡翅倒入水中焯一下去血沫捞起备用；
# d）热锅凉油下蒜末爆香后再放糖炒化成红色即可加进之前准备好的鸡翅翻煎均匀使其表面微黄并有焦黄色泽出现时再倒进生抽酱油继续翻煎一会儿让其充分吸收调料味道最后撒点食盐调味就可以关火盛盘了！"""

# # 使用正则表达式提取每个小点及其后面的内容
# pattern = r'(\d+\.\s*.*?)(?=\n\d+\.|\Z)'
# matches = re.findall(pattern, content, re.DOTALL)

# # 将结果存储为JSON数组
# json_array = []
# for match in matches:
#     point_number = match.split('.')[0].strip()
#     point_content = match.split('.', 1)[1].strip()
#     json_array.append({"point": point_number, "content": point_content})

# json_output = json.dumps(json_array, ensure_ascii=False, indent=4)

# print(json_output)

# import os
# import dashscope

# messages = [
#     {
#         "role": "user",
#         "content": [
#             # {"image": "https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg"},
#             # {"image": "https://dashscope.oss-cn-beijing.aliyuncs.com/images/tiger.png"},
#             # {"image": "https://dashscope.oss-cn-beijing.aliyuncs.com/images/rabbit.png"},
#              {"text": "你是谁"}
#         ]
#     }
# ]
# response = dashscope.MultiModalConversation.call(
#     # 若没有配置环境变量，请用百炼API Key将下行替换为：api_key="sk-xxx",
#     api_key="sk-f30f096e716f4bf3847df42b880801ed",
#     model='qwen-vl-max', # 此处以qwen-vl-max为例，可按需更换模型名称。模型列表：https://help.aliyun.com/zh/model-studio/getting-started/models
#     messages=messages
#     )
# print(response)

import os
import dashscope

messages = [
    {'role': 'system', 'content': 'You are a helpful assistant.'},
    {'role': 'user', 'content': '请发挥想象力，根据土豆，白菜，牛肉这些食材创造一个新菜，请以1.这道菜的菜谱，2.这道菜的呈现效果“的格式阐述，返回纯文本（不要返回Markdown符号），简明扼要，请认真思考。'}
    ]
response = dashscope.Generation.call(
    # 若没有配置环境变量，请用百炼API Key将下行替换为：api_key="sk-xxx",
    api_key="sk-f30f096e716f4bf3847df42b880801ed",
    model="qwen-max-2025-01-25", # 此处以qwen-plus为例，可按需更换模型名称。模型列表：https://help.aliyun.com/zh/model-studio/getting-started/models
    messages=messages,
    result_format='message',
    )
print(response)

# from http import HTTPStatus
# from urllib.parse import urlparse, unquote
# from pathlib import PurePosixPath
# import requests
# from dashscope import ImageSynthesis
# import os

# prompt = "菜名：田园三鲜炖，汤汁呈琥珀色浓稠质地，土豆块金黄微透，茄子保留紫亮表皮但内里吸饱汤汁，白菜叶嫩白透绿舒展如花瓣。表面撒少许葱花或香菜末，搭配油亮反光的汤汁，呈现温暖的家常感。"


# print('----sync call, please wait a moment----')
# rsp = ImageSynthesis.call(api_key="sk-f30f096e716f4bf3847df42b880801ed",
#                           model="wanx2.1-t2i-turbo",
#                           prompt=prompt,
#                           n=1,
#                           size='1024*1024')
# print('response: %s' % rsp)
# if rsp.status_code == HTTPStatus.OK:
#     # 在当前目录下保存图片
#     for result in rsp.output.results:
#         file_name = PurePosixPath(unquote(urlparse(result.url).path)).parts[-1]
#         with open('./img/create_recipe/%s' % file_name, 'wb+') as f:
#             f.write(requests.get(result.url).content)
# else:
#     print('sync_call Failed, status_code: %s, code: %s, message: %s' %
#           (rsp.status_code, rsp.code, rsp.message))